package com.hjm.project.agentInfo.kouFail.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.agentInfo.kouFail.domain.KouFail;
import com.hjm.project.agentInfo.kouFail.service.IKouFailService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.web.page.TableDataInfo;
import javax.annotation.Resource;

/**
 * 失败记录Controller
 * 
 * @author maker-platform
 * @date 2021-11-16
 */
@Controller
@RequestMapping("/agentInfo/kouFail")
public class KouFailController extends BaseController {
    private String prefix = "agentInfo/kouFail";

    @Resource
    private IKouFailService kouFailService;

    @RequiresPermissions("agentInfo:kouFail:view")
    @GetMapping()
    public String kouFail() {
        return prefix + "/kouFail";
    }

    /**
     * 查询失败记录列表
     */
    @RequiresPermissions("agentInfo:kouFail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(KouFail kouFail) {
        startPage();
        List<KouFail> list = kouFailService.selectKouFailList(kouFail);
        return getDataTable(list);
    }

    /**
     * 导出失败记录列表
     */
    @RequiresPermissions("agentInfo:kouFail:export")
    @Log(title = "失败记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(KouFail kouFail) {
        List<KouFail> list = kouFailService.selectKouFailList(kouFail);
        ExcelUtil<KouFail> util = new ExcelUtil<KouFail>(KouFail.class);
        return util.exportExcel(list, "kouFail");
    }

    /**
     * 新增失败记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存失败记录
     */
    @RequiresPermissions("agentInfo:kouFail:add")
    @Log(title = "失败记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(KouFail kouFail) {
        return toAjax(kouFailService.insertKouFail(kouFail));
    }

    /**
     * 修改失败记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
        KouFail kouFail = kouFailService.selectKouFailById(id);
        mmap.put("kouFail", kouFail);
        return prefix + "/edit";
    }

    /**
     * 修改保存失败记录
     */
    @RequiresPermissions("agentInfo:kouFail:edit")
    @Log(title = "失败记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(KouFail kouFail) {
        return toAjax(kouFailService.updateKouFail(kouFail));
    }

    /**
     * 删除失败记录
     */
    @RequiresPermissions("agentInfo:kouFail:remove")
    @Log(title = "失败记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(kouFailService.deleteKouFailByIds(ids));
    }

    /**
     * 失败再扣款
     */
    @RequiresPermissions("agentInfo:kouFail:edit")
    @Log(title = "失败再扣款", businessType = BusinessType.UPDATE)
    @PostMapping("/saveCk")
    @ResponseBody
    public AjaxResult saveCk(KouFail kouFail) throws Exception {
        int i = kouFailService.saveCk(kouFail);
        return toAjax(i);
    }


}
